package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.service.DishService;
import com.itheima.reggie.utils.Result;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/dish")
@Api(tags = "菜品相关接口")
public class DishController {
    @Resource
    private DishService dishService;

    @PostMapping
    public Result<String> addOneDish(@RequestBody DishDto dishDto) {
        return dishService.addOneDish(dishDto);
    }

    @GetMapping("/page")
    @ApiOperation("菜品分页查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录数", required = true),
            @ApiImplicitParam(name = "name", value = "菜品名称")
    }
    )

    public Result<Page<DishDto>> getPage(int page, int pageSize, String name) {
        return dishService.getPage(name, page, pageSize);
    }

    @GetMapping("/{id}")
    public Result<DishDto> getDish(@PathVariable("id") Long dishId) {
        return dishService.getDish(dishId);
    }

    @PutMapping
    public Result<String> updateDish(@RequestBody DishDto dishDto) {
        return dishService.updateDish(dishDto);
    }

    @GetMapping("/list")
    public Result<List<DishDto>> getDishList(Dish dish) {
        return dishService.getDishList(dish);
    }

    /**
     * 批量删除菜品
     *
     * @param ids 菜品id
     * @return String类型的通用返回数据
     */
    @DeleteMapping
    public Result<String> deleteDishes(@RequestParam List<Long> ids) {
        return dishService.deleteDishes(ids);
    }

    /**
     * 批量更改菜品的状态
     *
     * @param ids      要更改的所有菜品id
     * @param toStatus 要将这些菜品的状态改为toStatus
     * @return String类型的通用返回数据
     */
    @PostMapping("/status/{toStatus}")
    public Result<String> updateDishesStatus(@RequestParam List<Long> ids, @PathVariable int toStatus) {
        return dishService.updateDishesStatus(ids, toStatus);
    }
}
